﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Templates/Template2.Master" Inherits="System.Web.Mvc.ViewPage<SushiWeb.Models.Usuario>" %>

<asp:Content ID="Content2" ContentPlaceHolderID="menuContent" runat="server">
<%
    string[] menuArray = { "1", "0", "0", "0", "0"};
    Session["menuArray"] = menuArray;
%>
</asp:Content>


<asp:Content ID="Content1" ContentPlaceHolderID="body" runat="server">
    <script type="text/javascript">


        $(document).ready(function () {
            // validar formulario
            $("#loginForm").validate({
                submitHandler: function (form) {
                    submitForm("");
                },
                rules: {
                    Username: "required",
                    Contrasena: "required"

                }
            });

        });

        function submitForm() {

            var $form = $("#loginForm");

            $.ajax({
                type: "POST",
                url: $form.attr('action'),
                data: $form.serialize(),
                error: function (xhr, status, error) {
                    $.msgBox({
                        content: error,
                        type: "error"
                    });
                },
                success: function (data) {
                    $("#loading-div-background").hide();
                    if (data.tipoMensaje == 'INFO') {
                        $.msgBox({
                            content: data.mensaje,
                            type: "info",
                            afterClose: function () {
                                window.location = data.redirectTo;
                            }
                        });
                    } else if (data.tipoMensaje == 'WARN') {
                        $.msgBox({
                            content: data.mensaje,
                            type: "alert"
                        });
                    }

                },
                beforeSend: function (data) {
                    $("#loading-div-background").show();
                }
            });

            return false;
        }
    </script>

    <% using (Html.BeginForm("Autenticar", "Seguridad", FormMethod.Post, new { id = "loginForm", @class = "cmxform" }))
       {%>   
            <table style="width:auto">
                <tr >
                    <td class="style3" colspan="2">Login</td>
                    
                </tr>
                <tr>
                    <td class="style3">Usuario: </td>
                    <td class="style5">
                        <%: Html.TextBoxFor(model => Model.Username)%>
                    </td>

                </tr>
                <tr>
                    <td class="style3">Password: </td>
                    <td class="style5">
                        <%: Html.PasswordFor(model => Model.Contrasena)%>
                    </td>

                </tr>
                <tr>
                    <td class="style3" colspan="2">
                        <input id="btnSubmit" type="submit" value="Login" class="button"/>
                    </td>
                    
                </tr>
                <tr>
                    <td class="style3" colspan="2">
                        <a href="/Cliente/Clientes">Registrarse</a>
                    </td>
                    
                </tr>
            </table>
         <% } %>

</asp:Content>